package com.woshua.livedatabusmodel;

import android.arch.lifecycle.Observer;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.woshua.livedatabusmodel.event.LiveDataBus;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView tvContent=findViewById(R.id.tv_content);
        LiveDataBus.get().with("MainActivity",HuaWei.class).observe(this, new Observer<HuaWei>() {
            @Override
            public void onChanged(@Nullable HuaWei huaWei) {
                tvContent.setText(huaWei.getName());
            }
        });
    }

    /*
    * 发送消息
    * */
    public void sendMsgClick(View view) {
        HuaWei huaWei=new HuaWei("华为荣耀","XHUA_WEI");
        LiveDataBus.get().post("MainActivity",huaWei);
    }

    public void jumpNextPage(View view) {
        startActivity(new Intent(this,TwoActivity.class));
    }
}
